<template>
	<view>
		<view class="mui-content">
			<p class="check">订单信息核对：</p>
			<view class="info">
				<p><span></span><span>购买积分：</span><span id="number">{{chongzhiMoney}}</span></p>
				<p><span></span><span>到账积分：</span><span id="daozhang">{{daozhangMoney}}</span></p>
				<p><span></span><span>赠送积分：</span><span id="present">{{zengsongMoney}}</span></p>
				<p><span></span><span>应付金额：</span><span id="price">{{chongzhiMoney}}</span>元</p>
			</view>
			<p class="hint"></p>
			<view class="pay" @click="pay()">确认充值</view>
		</view>		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				chongzhiMoney:0,//充值金额
				daozhangMoney:0,//到账金额
				zengsongMoney:0,//赠送金额
			}
		},
		onLoad(opt) {
			this.chongzhiMoney = opt.money
			this.zengsongMoney = (this.chongzhiMoney*0.1).toFixed(2)
			this.daozhangMoney = (this.chongzhiMoney*1 + this.zengsongMoney*1).toFixed(2)
		},
		methods: {
			//确认订单充值积分
			pay(){
				this.$http.get('/chonzhi/toPayxcx',{
					userid:uni.getStorageSync('usersId'),
					money:this.chongzhiMoney,
					openId:uni.getStorageSync('openId')
				}).then(res => {
					console.log(res.data)
					if(res.data.code==200){
						let ddhao = res.data.data.ddhao;
						//调用微信支付
						let that = this;
						uni.requestPayment({
							appid: res.data.data.appId,  			// AppId，注意微信小程序、公众号 AppId 可能不一致
							nonceStr: res.data.data.nonceStr, 		// 随机字符串
							package: res.data.data.package,         // 固定值
							signType: res.data.data.signType,		// 签名类型
							timeStamp: res.data.data.timeStamp,     // 时间戳（单位：秒）
							paySign:res.data.data.paySign,
						    success(res) {
								uni.showToast({
									title: '支付成功',
									icon: 'success'
								});
								//支付成功调用回调函数
								that.$http.get('/chonzhi/notifyxcx',{
									orderId:ddhao
								}).then(res => {
									//支付成功，跳转页面
									uni.$emit('getJifenCenter');
									uni.navigateBack(2)
								})
							},
						    fail(e) {
								// console.log(e)
								uni.showToast({
									title: '支付失败',
									icon: 'error'
								});
							}
						})
					}else{
						this.$u.toast(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style>
	p {
		margin: 0;
	}
	.nav-header {
		background-color: #000000;
		color: white;
	}
	.nav-header h1 {
		text-align: left;
	}
	.nav-header a {
		color: white;
	}
	.nav-header h1 {
		text-align: left;
	}
	.nav-header a {
		color: white;
	}
	.check {
		line-height: 40px;
		border-bottom: 1px solid #E6E6E6;
		padding-left: 10px;
		color: #ada3a3;
	}
	.info p {
		background: #FFFFFF;
		height: 40px;
		line-height: 40px;
		border-bottom: 1px solid #E6E6E6;
		padding-left: 10px;
		color: #ada3a3;
	}
	.hint {
		line-height: 40px;
		text-align: center;
		font-size: 12px;
	}
	.pay {
		height: 40px;
		background: #FF6700;
		border-radius: 6px;
		text-align: center;
		line-height: 40px;
		color: #FFFFFF;
		margin: 20px 10px 0px 10px;
	}
</style>
